<?php
namespace gzapi\payment\controller;

use cmf\controller\PublicController;
use cmf\controller\BaseController;
use think\Validate;
use gzapi\common\business\Payment;

class CustomerController extends BaseController
{
    //方法验证参数
    protected $Train;
    protected $training_status = [
        '创建' => 1,
        '编辑' => 2,
        '提交' => 3,
    ];
    //输出签到页面
    public function sign()
    {
        $this->Payment = new Payment;
        //判断是否可以签到
        $get_data = input('param.');
        if(!isset($get_data['azd_id']) || !$get_data['azd_id'])
        {
            $this->error('信息错误');
        }
        if(!isset($get_data['train_id']) || !$get_data['train_id'])
        {
            $this->error('信息错误');
        }
        if(!isset($get_data['train_no']) || !$get_data['train_no'])
        {
            $this->error('信息错误');
        }
        //判断是否提交，是否在在开始培训时间之后（往前加一天）
        $where['training_no'] = $get_data['train_no'];
        $where['azd_id'] = $get_data['azd_id'];
        $where['row_id'] = $get_data['train_id'];
        $result = $this->Payment->isSign($where);
        if($result)
        {
            include (APP_PATH.'/payment/view/customer/404.html');
        }else{
            $this->assign('data',$get_data);
            include (APP_PATH.'/payment/view/customer/sign.html');
        }


    }

    //提交培训人员信息
    public function azdSign()
    {
        $this->Payment = new Payment;
        $get_data = input('param.');
        if(!isset($get_data['azd_id']) || !$get_data['azd_id'])
        {
            $this->error('信息错误');
        }
        if(!isset($get_data['train_id']) || !$get_data['train_id'])
        {
            $this->error('信息错误');
        }
        if(!isset($get_data['train_no']) || !$get_data['train_no'])
        {
            $this->error('信息错误');
        }
        if(!isset($get_data['train_person_name']) || !$get_data['train_person_name'])
        {
            $this->error('请填写姓名');
        }
        if(!isset($get_data['train_person_phone']) || !$get_data['train_person_phone'] || !preg_match("/^1[3456789]\d{9}$/", $get_data['train_person_phone']))
        {
            $this->error('请填写手机号');
        }
        if(!isset($get_data['train_person_post']) || !$get_data['train_person_post'])
        {
            $this->error('请填写职位');
        }
        if(!isset($get_data['affiliated_units']) || !$get_data['affiliated_units'])
        {
            $this->error('请填写所属单位');
        }
        $data['azd_id'] = $get_data['azd_id'];
        $data['train_id'] = $get_data['train_id'];
        $data['train_person_name'] = $get_data['train_person_name'];
        $data['train_person_phone'] = $get_data['train_person_phone'];
        $data['train_person_post'] = $get_data['train_person_post'];
        $data['affiliated_units'] = $get_data['affiliated_units'];
        $data['remark'] = $get_data['remark'];
        $data['train_no'] = $get_data['train_no'];
        $data['created_date'] = date('Y-m-d',time());
        $where['train_person_name'] = $get_data['train_person_name'];
        $where['train_person_phone'] = $get_data['train_person_phone'];
        $where['train_no'] = $get_data['train_no'];
        $result = $this->Payment->AzdSign($where,$data);
        if($result['code'])
        {
            $this->success("保存成功!");
        }else{
            $this->error($result['msg']);
        }
    }
}